import datetime

import pytz
from django.http import HttpResponse
from django.utils import timezone
from django_celery_beat.models import IntervalSchedule, PeriodicTask
from rest_framework.views import APIView

from xxx.response import JsonResponse


# Create your views here.
def index(request):
    naive = datetime.datetime.now(pytz.utc)
    naive2 = datetime.datetime.now()
    native3 = timezone.now()
    print(naive)
    print(naive2)
    print(native3)
    return HttpResponse("hello world")


class Task(APIView):
    def get(self, request, *args, **kwargs):
        id = request.GET.get('id')
        every = request.GET.get('every')
        if not id or not every:
            return JsonResponse({'error': 'require every or id'})

        task = IntervalSchedule()
        task.id = id
        task.every = every
        task.period = IntervalSchedule.SECONDS
        task.save()

        return JsonResponse({})
